{{include file="default/Public/header.html"}}
<script language="javascript">
$().ready(function (){
	var power_checkbox = $("#power_form input[type='checkbox']");
	var now_id = 0;
	power_checkbox.click(function (){
		var role_id = $("#role_id").val();
		if(!role_id>0) {
			alert('用户角色读取错误~！');
			return ;
		}
		var url = '{{U url="frbac/power?dosubmit=1&role_id="}}'+role_id;
		var thisobj = $(this);
		if($(this).attr('checked') == true) {
			var data = 'appname='+thisobj.attr('appname')+'&controller='+thisobj.attr('controller')+'&action='+thisobj.val()+'&do=add';			
		} else {
			var data = 'appname='+thisobj.attr('appname')+'&controller='+thisobj.attr('controller')+'&action='+thisobj.val()+'&do=remove';			
		}		
		$.ajax({
			url:url,
			data:data,
			cache:false,
			type:'post',
			success:function (msg){				
				if(msg == 'e') {
					alert('参数错误，数据发生异常，请刷新页面重新操作~！');
					if(thisobj.attr('checked') == true) {
							thisobj.attr('checked',false);
					} else {
						  thisobj.attr('checked',true);
					}
				} else if(msg == 'false'){
					alert('保存失败');
					if(thisobj.attr('checked') == true) {
						thisobj.attr('checked',false);
					} else {
						thisobj.attr('checked',true);
					}
				}
			},
			error:function (xhr, msg, errorThrown){
				alert('数据保存错误，请刷新页面重新授权~！');
					if(thisobj.attr('checked') == true) {
						thisobj.attr('checked',false);
					} else {
						thisobj.attr('checked',true);
					}
			},
			complete:function (){
				$("#working_gif_"+now_id).remove();				
			},			
			beforeSend:function (xhr){
				now_id ++;
				thisobj.parent().append('<img src="{{$smarty.const._PUBLIC_}}images/working.gif" id="working_gif_'+now_id+'" />');				
			}
		});
	});
});
</script>
<div id="pageTop">
	<div class="tabs"> 
		<ul>
			<li><a href="javascript:void(0);" class="selected" rel="tabsContent1">编辑权限</a></li>
			<li><a href='{{U url="fcache/act?isadmin=$isadmin"}}' >更新缓存</a></li>
		</ul>		
	</div>
</div>

<form id="power_form" method="post" action="{{U url='frbac/power?dosubmit=1'}}" >
<div id="pageCo">
	<div class="manageForm">
		<table cellpadding="0" cellspacing="0" class="tabcontent" id="tabsContent1">
			<tbody>
				<tr>
			      <th colspan="2"><h2>编辑角色权限(勾选以后会自动保权限信息)</h2></td>
			    </tr>
				<tr>
			      <td width="90" >角色名称:</td>
			      <td>{{$role_data.nickname}}</td>
			    </tr>
			    <tr>
			      <td width="90">所属应用:</td>
			      <td>        
			        <a href="javascript:;" onclick="$('.actions_panel_admin').show();$('.actions_panel_front').hide();">后台</a>
			        <a href="javascript:;" onclick="$('.actions_panel_admin').hide();$('.actions_panel_front').show();">前台</a>        
			      </td>
			    </tr>
			    <tr>
			      <td valign="top" width="90">编辑授权:</td>
			      <td>
			      <table class="actions_list" cellpadding="0" cellspacing="1">
			      {{foreach from=$data.admin item=v key=k}}      
			      <tr class="actions_panel_admin">
			        <th width="20%">{{$v.contorllername}}<span>{{$k}}</span></span></th>
			        <td>
			        <ul>
			        {{foreach from=$v.info item=v2}}
			          <li><input type="checkbox" name="info[{{$v2.controller}}][]" appname="{{$v2.appname}}" controller="{{$v2.controller}}" value="{{$v2.action}}" {{if in_array($role_data.name,$v2.allow)}}checked="checked"{{/if}} />{{$v2.name}}</li>
			        {{/foreach}}
			        </ul>
			        </td>
			      </tr>      
			     {{/foreach}}
			     {{foreach from=$data.front item=v key=k}}      
			      <tr style="display:none;" class="actions_panel_front">
			        <th width="20%">{{$v.contorllername}}<span>{{$k}}</span></span></th>
			        <td>
			        <ul>
			        {{foreach from=$v.info item=v2}}
			          <li><input type="checkbox" name="info[{{$v2.controller}}][]" appname="{{$v2.appname}}" controller="{{$v2.controller}}" value="{{$v2.action}}" {{if in_array($role_data.name,$v2.allow)}}checked="checked"{{/if}} />{{$v2.name}}</li>
			        {{/foreach}}
			        </ul>
			        </td>
			      </tr>      
			     {{/foreach}}
			      </table>    
			      </td>
			    </tr>
			</tbody>
			<tfoot>
				<tr>
					<td width="90" ></td>
					<td><input name="role_id" id="role_id" type="hidden" value="{{$role_data.role_id}}" /></td>
				</tr>
			</tfoot>
		</table>
	</div>	
</div>
</form>
{{include file="default/Public/footer.html"}}